﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
using Common;

namespace CentralMonitoring
{
    public class session
    {
        /// <summary>
        /// 当前详细页面的设备识别码
        /// </summary>
        public static string m_currentDeviceId = "";        
        public static string mServerIp = "39.164.32.237";
        public static int mServerPort = 1883;
        public static string mClientUUID = "MonitoringApp";
        public static string mXieYi = "MF";
        /// <summary>
        /// 远程固件升级
        /// </summary>
        public static string mSensorUUID = "HardwareApp";
        public static string mSubscribe = "/up";
        public static string mTopic = "/down";
        /// <summary>
        /// 记录设备状态
        /// </summary>
        public static List<Devicelist> m_dvList = new List<Devicelist>();
        public static List<DeviceAlgoList> m_algoList=new List<DeviceAlgoList>();
        public static DeviceStatus mDeviceStatus = new DeviceStatus();
        /// <summary>
        /// 保留未用
        /// </summary>
        /// <param name="temper"></param>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static double CalcVisStand(double temper,double a,double b)
        {
            //计算公式
            //var a=Math.log(Math.log(v1+0.6));
            //var b=Math.log(Math.log(v2+0.6));
            //b=(a-b)/(Math.log(t2+273）-Math.log(t1+273));
            //a=a+b*Math.log(t1+273);
            //form.v3.value=Math.exp(Math.exp(a-b*Math.log(t3+273)))-0.6;

            double vis40 = 0d;
            vis40 = Math.Exp(Math.Exp(a - b * Math.Log(temper + 273))) - 0.6;
            return vis40;

        }
        public static decimal CalcVis40(double temper, double vis, double a, double b, double st40)
        {
            try
            {
                double st_temper = CalcVisStand(temper, a, b);
                double wc_vis = Math.Round((vis - st_temper) / vis, 3);
                double vis40 = st40 + st40 * wc_vis;
                //lLogWrite.WriteLog("标准粘度:" + st_temper.ToString() + "误差值:" + wc_vis + "v40:" + vis40.ToString());
                if(vis40<0)
                    vis40 = Math.Abs(vis40);
                return (decimal)vis40;
            }
            catch (Exception ex)
            {
                return 0m;
            }
        }
        public static decimal CalcVis40(double temper,double vis, double temper1, double vis1)
        {
            //计算公式
            var a = Math.Log(Math.Log(vis + 0.6));
            var b = Math.Log(Math.Log(vis1 + 0.6));
            b = (a - b) / (Math.Log(temper1 + 273)-Math.Log(temper + 273));
            a = a + b * Math.Log(temper + 273);         
            double vis40 = 0d;
            vis40 = Math.Exp(Math.Exp(a - b * Math.Log(40 + 273))) - 0.6;
            if (vis40 == double.NaN)
            {
                
            }
            return (decimal)vis40;

        }       

    }
    public enum OprType
    {
        Add,
        Modify
    }
}
